home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1999 July: Mac OS SDK / Dev.CD Jul 99 SDK1.toast / Development Kits / Mac OS / QuickDraw3D 1.6 SDK / Mac SampleCode New for 1.6 / CompressedPixmapSample / Source / Events.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-05-18  |  3.8 KB  |  189 lines  |  [TEXT/CWIE]

  1. /****************************/
  2. /*        EVENTS            */
  3. /* By Brian Greenstone      */
  4. /****************************/
  5.  
  6.  
  7. /***************/
  8. /* EXTERNALS   */
  9. /***************/
  10. #include <ToolUtils.h>
  11. #include <Menus.h>
  12. #include <MacWindows.h>
  13. #include <Controls.h>
  14.  
  15. #include "myglobals.h"
  16. #include "myevents.h"
  17. #include "mymenus.h"
  18. #include "misc.h"
  19. #include "qd3d_support.h"
  20. #include "process.h"
  21.  
  22.  
  23. extern    WindowPtr                gModelWindow;
  24. extern    QD3DSetupOutputType        gModelViewInfo;
  25.  
  26. /****************************/
  27. /*    PROTOTYPES            */
  28. /****************************/
  29.  
  30. static void DoHighLevelEvent(void);
  31. static Boolean IsDAWindow(WindowPtr whichWindow);
  32. static OSErr  hasGotRequiredParams(AppleEvent *appEvent);
  33. static void    HandleMouseDown(void);
  34.  
  35.  
  36. /****************************/
  37. /*    CONSTANTS             */
  38. /****************************/
  39.  
  40.  
  41. /**********************/
  42. /*     VARIABLES      */
  43. /**********************/
  44.  
  45. EventRecord    gTheEvent;
  46.  
  47.  
  48. /******************** HANDLE EVENTS ************************/
  49.  
  50. void HandleEvents(void)
  51. {
  52. char    theChar;
  53. GrafPtr    oldPort;
  54.         
  55.     WaitNextEvent(everyEvent,&gTheEvent, 0, 0);
  56.                 
  57.     switch (gTheEvent.what)
  58.     {
  59.         case    nullEvent:
  60.                 DoModelWindowNullEvent();
  61.                 break;
  62.                 
  63.         case    mouseDown:
  64.                 HandleMouseDown();
  65.                 break;
  66.                 
  67.         case    keyDown:
  68.         case    autoKey:
  69.                 theChar    = gTheEvent.message & charCodeMask;
  70.                 if    ((gTheEvent.modifiers & cmdKey) != 0)
  71.                     HandleMenuChoice(MenuKey(theChar));
  72.                 break;
  73.                 
  74.         case    updateEvt:
  75.                 if (!IsDAWindow((WindowPtr)gTheEvent.message))
  76.                 {
  77.                     GetPort (&oldPort);
  78.                     SetPort ((WindowPtr)gTheEvent.message);
  79.                     BeginUpdate((WindowPtr)gTheEvent.message);
  80.                     DrawControls((WindowPtr)gTheEvent.message);
  81.                     
  82.                     if ((WindowPtr)gTheEvent.message == gModelWindow)
  83.                         DrawModelWindow();
  84.                                             
  85.                     EndUpdate((WindowPtr)gTheEvent.message);
  86.                     SetPort(oldPort); 
  87.                 }
  88.                 else 
  89.                 {
  90.                     BeginUpdate((WindowPtr)gTheEvent.message);
  91.                     EndUpdate((WindowPtr)gTheEvent.message);
  92.                 }
  93.                 break;
  94.                 
  95.         case    kHighLevelEvent:
  96.                 DoHighLevelEvent();
  97.                 break;
  98.     }
  99. }
  100.  
  101.  
  102. /**************** DO HIGH LEVEL EVENT *****************/
  103.  
  104. static void DoHighLevelEvent(void)
  105. {
  106. OSErr    myErr;
  107.  
  108.     myErr = AEProcessAppleEvent(&gTheEvent);
  109. }
  110.  
  111.  
  112. /************** HANDLE MOUSE DOWN *******************/
  113.  
  114. static void HandleMouseDown(void)
  115. {
  116.     WindowPtr        whichWindow;
  117.     short             thePart;
  118.     long            menuChoice, windSize;
  119.     
  120.     thePart    =    FindWindow(gTheEvent.where, &whichWindow);
  121.     switch(thePart)
  122.     {
  123.         case    inMenuBar:
  124.                 menuChoice = MenuSelect(gTheEvent.where);
  125.                 HandleMenuChoice(menuChoice);
  126.                 break;
  127.                 
  128.         case    inSysWindow:
  129.                 SystemClick(&gTheEvent, whichWindow);
  130.                 break;
  131.                 
  132.         case    inDrag:
  133.                 DragWindow(whichWindow,gTheEvent.where, &qd.screenBits.bounds);
  134.                 break;
  135.                 
  136.         case    inGoAway:
  137.                 DisposeWindow (whichWindow);
  138.                 break;
  139.                 
  140.         case    inContent:
  141.                 SelectWindow(whichWindow);
  142.  
  143.                 break;
  144.                 
  145.         case    inGrow:
  146.                 windSize = GrowWindow(whichWindow, gTheEvent.where,
  147.                                     &(**GetGrayRgn()).rgnBBox);
  148.                 if (windSize != 0)
  149.                 {
  150.                     SetPort(whichWindow);
  151.                     EraseRect(&whichWindow->portRect);
  152.                     SizeWindow(whichWindow,LoWord(windSize),
  153.                                 HiWord(windSize), NORMAL_UPDATES);
  154.                     InvalRect(&whichWindow->portRect);
  155.                     
  156.                     if (whichWindow == gModelWindow)            // see if change Skeleton window
  157.                     {
  158.                         QD3D_ChangeDrawSize(&gModelViewInfo);
  159.                     }
  160.                 } 
  161.                 break;
  162.     }
  163. }
  164.  
  165.  
  166. /**************** IS DA WINDOW ***********************/
  167.  
  168. static Boolean IsDAWindow(WindowPtr whichWindow)
  169. {
  170.     if    (whichWindow == nil)
  171.         return (false);
  172.     else
  173.         return (((WindowPeek)whichWindow)->windowKind < 0);
  174. }
  175.  
  176.  
  177.  
  178.  
  179. /*********************** MY APPLE EVENT: QUIT APPLICATION *************************/
  180.  
  181. pascal OSErr MyAE_QuitApplication(AppleEvent *theAppleEvent, AppleEvent *reply,
  182.                             SInt32 handlerRefcon)
  183. {
  184.     #pragma unused(theAppleEvent, reply, handlerRefcon)
  185.  
  186.     CleanQuit();
  187.     return(noErr);
  188. }
  189.